<#
项目初始化（原生 PowerShell）
用途：初始化 AIDevFlow 配置，写入 config/rules.env 并记录本地时间戳。
用法：
  pwsh -File scripts/windows/custom_init.ps1 [-langs "java,python"] [-style mimic] [-force]
#>
param(
  [string]$langs = 'java,python',
  [string]$style = 'mimic',
  [switch]$force
)

function LocalTimestamp() { (Get-Date).ToString('yyyy-MM-dd HH:mm:ss') }

$WindowsDir = Split-Path -Parent $PSCommandPath
$ScriptsDir = Split-Path -Parent $WindowsDir
$RepoDir = Split-Path -Parent $ScriptsDir

$cfgDir = Join-Path $RepoDir 'config'
if (!(Test-Path $cfgDir)) { $cfgDir = Join-Path $RepoDir 'config' }
New-Item -ItemType Directory -Force -Path $cfgDir | Out-Null
$envFile = Join-Path $cfgDir 'rules.env'

$content = @()
if (-not $force -and (Test-Path $envFile)) { $content += Get-Content -Raw $envFile }
$content = $content | Where-Object { $_ -notmatch '^(INIT_TIMESTAMP|SUPPORTED_LANGS|DEFAULT_STYLE)=' }
$content += "INIT_TIMESTAMP=" + (LocalTimestamp())
$content += "SUPPORTED_LANGS=$langs"
$content += "DEFAULT_STYLE=$style"
Set-Content -Path $envFile -Value ($content -join "`n")

Write-Host "已初始化配置：$envFile"
Write-Host "INIT_TIMESTAMP=`"$(LocalTimestamp())`"; SUPPORTED_LANGS=`"$langs`"; DEFAULT_STYLE=`"$style`""
exit 0
